import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
  name: 'dateTime',
})
export class DateTimePipe implements PipeTransform {
  transform(value: any, pre: string) {
    if (value && pre) {
      value.toString().length > 10 ? value : value * 10;
      let _date = new Date(value);
      let Y = _date.getFullYear();
      let M = _date.getMonth() + 1 > 10 ? _date.getMonth() : "0" + (_date.getMonth() + 1);
      let D = _date.getDate() > 10 ? _date.getDate() : "0" + _date.getDate();
      let h = _date.getHours() > 12 ? "0" + (_date.getHours() - 12) : _date.getHours();
      let m = _date.getMinutes() > 10 ? _date.getMinutes() : "0" + _date.getMinutes();
      let s = _date.getSeconds() > 10 ? _date.getSeconds() : "0" + _date.getSeconds();
      pre = pre.replace('yyyy', `${Y}`)
        .replace('MM', `${M}`)
        .replace('dd', `${D}`)
        .replace('hh', `${h}`)
        .replace('mm', `${m}`)
        .replace('ss', `${s}`)
      return pre;
      // switch (pre) {
      //   case "yyyy":
      //     return `${Y}`;
      //   case "yyyy-MM":
      //     return `${Y}-${M}`;
      //   case "yyyy-MM-dd":
      //     return `${Y}-${M}-${D}`;
      //   case "yyyy-MM-dd hh":
      //     return `${Y}-${M}-${D} ${h}`;
      //   case "yyyy-MM-dd hh:mm":
      //     return `${Y}-${M}-${D} ${h}:${m}`;
      //   case "yyyy-MM-dd hh:mm:ss":
      //     return `${Y}-${M}-${D} ${h}:${m}:${s}`;
      //   default:
      //     return `${Y}-${M}-${D} ${h}:${m}:${s}`;
      // }
    }
  }
}
